package lry.sql;

import com.lry.ExpressionType;
import com.lry.consumer.ConsumeStatus;
import com.lry.consumer.DefaultMqConsumer;
import com.lry.consumer.MessageListenerConcurrently;
import com.lry.message.MessageExt;

import java.util.List;

public class BasicConsumer {
    public static void main(String[] args) {

        DefaultMqConsumer consumer = new DefaultMqConsumer("localhost:8084","group","c1");

        consumer.subscribe("topic", ExpressionType.SQL92+"a between 0 and 3");

        final int[] ai = {0};

        consumer.registerMessageListener(new MessageListenerConcurrently() {
            @Override
            public ConsumeStatus consumeMessage(List<MessageExt> messages) {

                for (MessageExt message : messages) {
                    System.out.println(new String(message.getBody()));
                }

                ai[0] += messages.size();
                System.out.println("共收到消息="+ ai[0]);
                return ConsumeStatus.CONSUME_SUCCESS;
            }
        });

        consumer.start();
    }
}
